package com.sina.finance.api.framework.utils;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @File name : responseUtils
 * @Description :
 * @Creator : cuiyong
 * @CreateTime : 15/11/9 11:03
 * @Version : 1.0
 * @Update records:
 * 1.0 15/11/9 by cuiyong: Created
 * All rights served : SINA Corporation
 */
public class ResponseUtils {
    public static void writeToResponse(String contentType, int responseCode, String content, HttpServletResponse httpResponse) {
        httpResponse.setStatus(responseCode);
        httpResponse.setContentType(contentType);
        httpResponse.setCharacterEncoding("utf-8");
        try {
            httpResponse.getWriter().println(content);

        } catch (IOException e) {
            throw new RuntimeException("写入返回内容出错", e);
        }
    }

    public static void responsePlainText(String content, HttpServletResponse httpResponse) {
        ResponseUtils.writeToResponse("text/plain", HttpServletResponse.SC_OK, content, httpResponse);
    }
}
